import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: zhongyisheng
 * Date: 2024-06-24
 * Time: 15:38
 */
public class Test {



    public static void bubbleSort(int[] arr){
        for (int i = 0; i < arr.length-1; i++) {
            boolean flg = false;
            for (int j = 0; j < arr.length - i - 1; j++) {
                if( arr[j] > arr[j+1]){
                    int tmp = arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=tmp;
                    flg = true;
                }
            }
            if (flg == false) {
                return;
            }
        }
    }
    public static void main(String[] args) {
        int[] arr = {9,8,7,6,5,4,3,2,1};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }
}
